/**
 * @Time    : 2021/5/18 10:56
 * @Author  : Rich Chen
 * @License : Software business license
 * @Site    : www.rich-f.com
 * @File    : logger.js
 * @Software: Rich Web Platform
 * @Function: 日志设置
 * @Version : 1.0
 **/
const logger = require('log4js');

const ptn = "%[[%d{yyyy-MM-dd hh:mm:ss}] [%p] [%X{sid}] [%f{1} %l]- %m%]";
logger.configure({
    pm2: true,
    pm2InstanceVar: 'INSTANCE_ID',
    "appenders": {
        "console": {
            "type": "console",
            "layout": {
                "type": "pattern",
                "pattern": ptn
            },
        },
        "info": {
            "type": "dateFile",
            "filename": "./logs/info",
            "encoding": "utf-8",
            "pattern": "yyyy-MM-dd-hh.log",
            "maxLogSize": 20000000,
            "alwaysIncludePattern": true,
            "layout": {
                "type": "pattern",
                "pattern": ptn
            },
            "compress": true,
            "keepFileExt": true,
            "daysToKeep": 30
        },
        "maxInfo": {
            "type": "logLevelFilter",
            "appender": "info",
            "level": "debug",
            "maxLevel": "error"
        },
        "error": {
            "type": "dateFile",
            "filename": "./logs/error-",
            "pattern": "yyyy-MM-dd.log",
            "maxLogSize": 20000000,
            "encoding": "utf-8",
            "alwaysIncludePattern": true,
            "layout": {
                "type": "pattern",
                "pattern": ptn
            },
            "compress": true,
            "keepFileExt": true,
            "daysToKeep": 30
        },
        "minError": {
            "type": "logLevelFilter",
            "appender": "error",
            "level": "error"
        }
    },
    "categories": {
        "default": {
            "appenders": [
                "console",
                "maxInfo",
                "minError"
            ],
            "level": "debug",
            "enableCallStack": true
        }
    }
});


module.exports = {logger};




